package com.ny.zmb.openapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.mzlion.easyokhttp.HttpClient;
import com.ny.zmb.openapi.constant.PHPConstant;
import com.ny.zmb.openapi.controller.entity.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ys/wx")
@CrossOrigin
public class YsWxController {


    /**
     * 微信登录
     * @param code
     * @return
     */
    @GetMapping("login")
    public Result login(String code){
        String baseUrl = PHPConstant.wx_url
                .replace("APPID",PHPConstant.APPID)
                .replace("SECRET",PHPConstant.my)
                .replace("JSCODE",code);
        String s = HttpClient.get(baseUrl).execute().asString();
        return Result.ok(JSONObject.toJSONString(s));
    }
}
